//
//  AddOtherChargeListSubView.m
//  HondaPro_2
//
//  Created by Eric on 13-6-28.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "AddOtherChargeListSubView.h"

@interface AddOtherChargeListSubView ()

//创建控件
-(void)createStaticLbls;
-(void)createBtn;
-(void)createTextField;
-(void)createTableViewDis;

//刷新控件内容
-(void)freshenViewDis;

//回调方法
-(void)qitafeiyongleixingBtnPressed:(UIButton *)sender;
-(void)qitafeiyongdengluBtnPressed:(UIButton *)sender;
-(void)feiYongLeiXingBtnPressed:(UIButton *)sender;

@end

@implementation AddOtherChargeListSubView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        [self createStaticLbls];
        [self createTextField];
        [self createBtn];
        [self createTableViewDis];
        
        //注册接口消息
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getOtherChargeList:) name:MM_GET_OTHER_CHARGE_LIST_ object:nil];
        
        //初始化修理类型
        self.arrOriginalDataForRepairType = [[HelpClass returnTheDataByJsonFileAndJustForTestWithFileName:@"indication_repairType" andType:@"json"] objectForKey:@"repairTypeList"];
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    NSLog(@"drawRect AddOtherChargeListSubView ...");
    
    [self freshenViewDis];
}

#pragma mark - 创建控件

-(void)createStaticLbls
{
    //创建label
    UILabel *feiyongleixingLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
    feiyongleixingLbl.backgroundColor = [UIColor clearColor];
    feiyongleixingLbl.textColor = [UIColor grayColor];
    feiyongleixingLbl.font = [UIFont fontWithName:@"ArialMT" size:16];
    feiyongleixingLbl.text = @"费用类型：";
    [feiyongleixingLbl setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:feiyongleixingLbl];
    
    UILabel *feiyongmingchengLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 350, 80, 30)];
    feiyongmingchengLbl.backgroundColor = [UIColor clearColor];
    feiyongmingchengLbl.textColor = [UIColor grayColor];
    feiyongmingchengLbl.font = [UIFont fontWithName:@"ArialMT" size:16];
    feiyongmingchengLbl.text = @"费用名称：";
    [feiyongmingchengLbl setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:feiyongmingchengLbl];
    
    UILabel *feiyongjineLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, 80, 30)];
    feiyongjineLbl.backgroundColor = [UIColor clearColor];
    feiyongjineLbl.textColor = [UIColor grayColor];
    feiyongjineLbl.font = [UIFont fontWithName:@"ArialMT" size:16];
    feiyongjineLbl.text = @"费用金额：";
    [feiyongjineLbl setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:feiyongjineLbl];
}

-(void)createBtn
{
//    UIButton *feiyongleixingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    feiyongleixingBtn.frame = CGRectMake(240, 1, 30, 28);
//    [feiyongleixingBtn setImage:[UIImage imageNamed:@"mm_arrowDown.jpg"] forState:UIControlStateNormal];
//    [feiyongleixingBtn addTarget:self action:@selector(qitafeiyongleixingBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:feiyongleixingBtn];
    
    UILabel * feiYongLeiXingBtnBottomLbl = [[UILabel alloc] initWithFrame:CGRectMake(72+8, 3, 150, 34)];
    feiYongLeiXingBtnBottomLbl.backgroundColor = [UIColor grayColor];
    [self addSubview:feiYongLeiXingBtnBottomLbl];
    
    feiYongLeiXingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    feiYongLeiXingBtn.frame = CGRectMake(70+1+8, 0, 154-2, 40);
    [feiYongLeiXingBtn setBackgroundImage:[UIImage imageNamed:@"10.png"] forState:UIControlStateNormal];
    feiYongLeiXingBtn.backgroundColor = [UIColor clearColor];
    [feiYongLeiXingBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    feiYongLeiXingBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [feiYongLeiXingBtn addTarget:self action:@selector(feiYongLeiXingBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:feiYongLeiXingBtn];
    
    UIButton *qitafeiyongdengluBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qitafeiyongdengluBtn.frame = CGRectMake(610, 350, 120, 40);
    [self setUpTheStateBtnByBtn:qitafeiyongdengluBtn andState:YES];
    [qitafeiyongdengluBtn setTitle:@"其它费用登录" forState:UIControlStateNormal];
    [qitafeiyongdengluBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    qitafeiyongdengluBtn.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:16];
    [qitafeiyongdengluBtn addTarget:self action:@selector(qitafeiyongdengluBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:qitafeiyongdengluBtn];
}

-(void)feiYongLeiXingBtnPressed:(UIButton *)sender
{
    NSLog(@"feiYongLeiXingBtnPressed !!!");
    
    //创建下拉菜单
    [self createThePopViewControl:sender];
    
    //刷新下拉菜单的数据
    contentCon.list = _arrDataPopViewToDis;
    [contentCon.myTableView reloadData];
}

-(void)createTextField
{
//    feiyongleixingTxt = [[UITextField alloc] initWithFrame:CGRectMake(70, 0, 200, 30)];
//    feiyongleixingTxt.borderStyle = UITextBorderStyleLine;
//    feiyongleixingTxt.textColor = [UIColor grayColor];
//    feiyongleixingTxt.font = [UIFont fontWithName:@"ArialMT" size:16];
//    [self addSubview:feiyongleixingTxt];
    
    feiyongmingchengTxt = [[UITextField alloc] initWithFrame:CGRectMake(80, 350, 500, 30)];
    feiyongmingchengTxt.borderStyle = UITextBorderStyleLine;
    feiyongmingchengTxt.textColor = [UIColor grayColor];
    feiyongmingchengTxt.font = [UIFont fontWithName:@"ArialMT" size:16];
    feiyongmingchengTxt.delegate = self;
    [self addSubview:feiyongmingchengTxt];
    
    feiyongjineTxt = [[UITextField alloc] initWithFrame:CGRectMake(80, 400, 500, 30)];
    feiyongjineTxt.borderStyle = UITextBorderStyleLine;
    feiyongjineTxt.textColor = [UIColor grayColor];
    feiyongjineTxt.font = [UIFont fontWithName:@"ArialMT" size:16];
    feiyongjineTxt.delegate = self;
    [self addSubview:feiyongjineTxt];
}

-(void)createTableViewDis
{
    UILabel *bottomLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, self.frame.size.width, 50)];
    bottomLbl.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    bottomLbl.textColor = [UIColor grayColor];
    bottomLbl.font = [UIFont fontWithName:@"ArialMT" size:16];
    bottomLbl.text = @"名称";
    [self addSubview:bottomLbl];
    
    tableViewDis = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, self.frame.size.width, 220)];
    
    tableViewDis.delegate = self;
    tableViewDis.dataSource = self;
    
    tableViewDis.backgroundColor = [UIColor clearColor];
    
    [self addSubview:tableViewDis];
}

#pragma mark - tableView dataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5+[_arrDataTableViewToDis count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (nil == cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    //cell的风格是：浅浅灰色和浅灰色间隔出现，第一行是浅灰色
    NSInteger row = [indexPath row];
    switch (row%2)
    {
        case 0:
            //浅灰色
            cell.contentView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
            break;
        case 1:
            //浅浅灰色
            cell.contentView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
            break;
            
        default:
            break;
    }
    
    //设置label的字体颜色
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = [UIColor grayColor];
    
    if (row<[_arrDataTableViewToDis count])
    {
        cell.textLabel.text = [[_arrDataTableViewToDis objectAtIndex:row] objectForKey:@"otherChargeName"];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
    }
    else
    {
        cell.textLabel.text = @"";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}

#pragma mark - tableView delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = [indexPath row];
    
    //
    if (row<[_arrDataTableViewToDis count])
    {
        _nCurrentRowSel = row;
        
        feiyongmingchengTxt.text = [self getOtherChargeTypeStrByIdRowNumber:_nCurrentRowOnOtherChargeSel andNameRowNumber:_nCurrentRowSel];
    }
}

#pragma mark - 刷新控件内容

-(void)freshenViewDis
{
    _nCurrentRowOnOtherChargeSel = -1;
    _nCurrentRowSel = -1;
    
//    NSArray *_arrOriginalData;
//    NSMutableArray *_arrDataPopViewToDis;
//    NSMutableArray *_arrDataTableViewToDis;
//    
    //刷新视图
    _arrOriginalData = nil;
    _arrDataPopViewToDis = nil;
    _arrDataTableViewToDis = nil;
    [tableViewDis reloadData];
    
    //请求数据
    [HelpClass getWebServiceDataByString:MM_GET_OTHER_CHARGE_LIST_ andArrObject:nil];
    
    feiyongjineTxt.delegate = self;
}

#pragma mark - 回调方法

-(void)qitafeiyongleixingBtnPressed:(UIButton *)sender
{
    NSLog(@"qitafeiyongleixingBtnPressed !!!");
}

-(void)qitafeiyongdengluBtnPressed:(UIButton *)sender
{
    NSLog(@"qitafeiyongdengluBtnPressed !!!");
    
    if (
        (feiyongmingchengTxt.text == nil
         ||
         [feiyongmingchengTxt.text isEqualToString:@""])
        ||
        (feiyongjineTxt.text == nil
         ||
         [feiyongjineTxt.text isEqualToString:@""])
        )
    {
        //提示信息－－－信息填写不完整！
        UIAlertView *alerVeiw = [[UIAlertView alloc] initWithTitle:@"保存失败信息" message:@"信息填写不完整！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alerVeiw show];
        
        return;
    }
    
    if (![self otherChargeNotRepeat])
    {
        //提示信息－－－费用已存在！
        UIAlertView *alerVeiw = [[UIAlertView alloc] initWithTitle:@"保存失败信息" message:@"费用已存在！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alerVeiw show];
        
        return;
    }
    
    NSString *strOtherChargeType = @"";
    NSString *strOtherChargeSubConrtractCode = @"";
    
    if (_nCurrentRowOnOtherChargeSel == -1)
    {
        //提示稍等，正在获取数据，return
        
        return;
    }
    else
    {
        strOtherChargeType = [[_arrOriginalData objectAtIndex:_nCurrentRowOnOtherChargeSel] objectForKey:@"otherChargeTypeId"];
    }
        
    if (_nCurrentRowSel != -1 && (NSInteger)([[[_arrOriginalData objectAtIndex:_nCurrentRowOnOtherChargeSel] objectForKey:@"otherChargeNameList"] count]-1) >= _nCurrentRowSel)
    {
        strOtherChargeSubConrtractCode = [[_arrDataTableViewToDis objectAtIndex:_nCurrentRowSel] objectForKey:@"subcontractCode"];
    }
    
    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
    NSString *strNumber = [NSString stringWithFormat:@"%i",[self getTheMaxNumber]+1];
        
    NSDictionary *dicTmp = [NSDictionary dictionaryWithObjectsAndKeys:
                            strNumber,@"otherChargenumber",
                            feiyongmingchengTxt.text,@"chargeName",
                            feiyongjineTxt.text,@"chargeMoney",
                            strOtherChargeType,@"chargeTypeCode",
                            strOtherChargeSubConrtractCode,@"subcontractCode",
                            [NSString stringWithFormat:@"%i",[self isWarrantyByServiceInIndication]],@"isWarranty", nil];
    
    //更新业务模型
    NSLog(@"%@",modelIns.arrForResults);
    
    NSMutableArray *arrRepairList = [NSMutableArray arrayWithArray:[[[[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults] objectForKey:@"indicationList"] objectAtIndex:modelIns.nRowForIndicationList] objectForKey:@"otherChargeList"]];
    [arrRepairList addObject:dicTmp];
    
    NSMutableDictionary *dicIndicationList = [NSMutableDictionary dictionaryWithDictionary:[[[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults] objectForKey:@"indicationList"] objectAtIndex:modelIns.nRowForIndicationList]];
    [dicIndicationList setObject:arrRepairList forKey:@"otherChargeList"];
    
    NSMutableArray *arrIndicationList = [NSMutableArray arrayWithArray:[[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults] objectForKey:@"indicationList"]];
    [arrIndicationList setObject:dicIndicationList atIndexedSubscript:modelIns.nRowForIndicationList];
    
    NSMutableDictionary *dicResults = [NSMutableDictionary dictionaryWithDictionary:[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults]];
    [dicResults setObject:arrIndicationList forKey:@"indicationList"];
    
    NSMutableArray *arrResults = [NSMutableArray arrayWithArray:modelIns.arrForResults];
    [arrResults setObject:dicResults atIndexedSubscript:modelIns.nRowForResults];
    
    modelIns.arrForResults = [NSMutableArray arrayWithArray:arrResults];
    
    NSLog(@"%@",modelIns.arrForResults);
    
    //更新完数据后刷新界面
    [[NSNotificationCenter defaultCenter] postNotificationName:SECOND_OTHER_CHARGE_LIST_MSG_ object:nil];
}

//设置按钮的状态
-(void)setUpTheStateBtnByBtn:(UIButton *)btn andState:(BOOL)state
{
    if (YES == state)
    {
        [btn setBackgroundImage:[UIImage imageNamed:@"mm_red_btn.png"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    else
    {
        [btn setBackgroundImage:[UIImage imageNamed:@"mm_gray_btn.png"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    }
}

//创建下拉菜单方法
-(void)createThePopViewControl:(UIButton *)sender
{
    if (!contentCon)
    {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    
    popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:222 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    
    [popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [popCon setPopoverContentSize:CGSizeMake(sender.frame.size.width, 280)];
    
    [popCon presentPopoverFromRect:CGRectMake(40, 15, 70, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

#pragma mark - 代理方法
//弹出的回调方法
-(void)selectDelegate:(NSInteger)row btn:(UIButton *)btn
{
    _nCurrentRowOnOtherChargeSel = row;
    _nCurrentRowSel = 0;
    
    //根据选中的行，更新表单要显示的数据，刷新表单数据
    _arrDataTableViewToDis = [NSMutableArray arrayWithArray:[[_arrOriginalData objectAtIndex:row] objectForKey:@"otherChargeNameList"]];
    
    //调用显示其它费用名称的方法,如果类型名称列表不为空，默认显示类型名称列表中下标为0的汉字字符串
    NSString *strTmp = [self getOtherChargeTypeStrByIdRowNumber:_nCurrentRowOnOtherChargeSel andNameRowNumber:_nCurrentRowSel];
    feiyongmingchengTxt.text = strTmp;
    
    //刷新表单的数据
    [tableViewDis reloadData];

    [popCon dismissPopoverAnimated:YES];
    popCon = nil;
}

//请求数据回调方法
-(void)getOtherChargeList:(NSNotification*)notification
{
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    
    _arrOriginalData = [theJson objectForKey:@"otherChargeTypeList"];
    _arrDataPopViewToDis = [NSMutableArray array];
    
    if (nil == _arrOriginalData)
    {
        //如果获取数据失败则继续获取数据
        [HelpClass getWebServiceDataByString:MM_GET_OTHER_CHARGE_LIST_ andArrObject:nil];
        return;
    }
    
    //请求数据成功，初始化列表数据
    _nCurrentRowOnOtherChargeSel = 0;
    _nCurrentRowSel = 0;
    feiyongmingchengTxt.text = [self getOtherChargeTypeStrByIdRowNumber:_nCurrentRowOnOtherChargeSel andNameRowNumber:_nCurrentRowSel];
    [feiYongLeiXingBtn setTitle:[[_arrOriginalData objectAtIndex:_nCurrentRowOnOtherChargeSel] objectForKey:@"otherChargeTypeName"] forState:UIControlStateNormal];
    [tableViewDis reloadData];
    
    for (int i = 0; i<[_arrOriginalData count]; i++)
    {
        [_arrDataPopViewToDis addObject:[[_arrOriginalData objectAtIndex:i] objectForKey:@"otherChargeTypeName"]];
    }
}

//判断作业指示的 服务类型 是否是保修
-(BOOL)isWarrantyByServiceInIndication
{
    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
    NSString *str = [[[[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults] objectForKey:@"indicationList"] objectAtIndex:modelIns.nRowForIndicationList] objectForKey:@"serviceType"];
    NSRange range = [[self getNameByServiceId:str] rangeOfString:@"保修"];
    if (range.length == [@"保修" length])
    {
        return YES;
    }
    return NO;
}

//判断是否重复添加相同费用
-(BOOL)otherChargeNotRepeat
{
    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
    
    NSArray *arrOtherChargeList = [[[[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults] objectForKey:@"indicationList"] objectAtIndex:modelIns.nRowForIndicationList] objectForKey:@"otherChargeList"];
    
    for (int i = 0; i<[arrOtherChargeList count]; i++)
    {
        if ([[[arrOtherChargeList objectAtIndex:i] objectForKey:@"chargeName"] isEqualToString:feiyongmingchengTxt.text])
        {
            return NO;
        }
    }
    
    return YES;
}

//返回其他费用类型名称要显示的字符串
-(NSString *)getOtherChargeTypeStrByIdRowNumber:(NSInteger)IdNum andNameRowNumber:(NSInteger)nameNum
{
    //(1)如果费用名称列表为空，费用名称 返回 费用类型的名字 return
    if (0 == [[[_arrOriginalData objectAtIndex:IdNum] objectForKey:@"otherChargeNameList"] count])
    {
        NSLog(@"%@",_arrOriginalData);
        NSString *strTmp = [[_arrOriginalData objectAtIndex:IdNum] objectForKey:@"otherChargeTypeName"];
        return strTmp;
    }
    
//    //(2)如果控件费用名称不为空，并且 控件费用名称 和 费用名称列表里边的名称 不同，返回控件费用名称，return
//    if (![feiyongmingchengTxt.text isEqualToString:@""]
//        ||
//        ![feiyongmingchengTxt.text isEqualToString:[[[[_arrOriginalData objectAtIndex:IdNum] objectForKey:@"otherChargeNameList"] objectAtIndex:nameNum] objectForKey:@"otherChargeName"]])
//    {
//        return feiyongmingchengTxt.text;
//    }
    
    //(3)返回 费用名称 列表中 行号为 nameNum 的字符串
    return [[[[_arrOriginalData objectAtIndex:IdNum] objectForKey:@"otherChargeNameList"] objectAtIndex:nameNum] objectForKey:@"otherChargeName"];
}

//remove 所有注册的消息
-(void)removeAllObserver
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if (textField == feiyongmingchengTxt)
    {
        return YES;
    }
    
    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:@".0123456789\n"]invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
    BOOL canChange = [string isEqualToString:filtered];
    
    [feiyongmingchengTxt setEnabled:YES];

    return canChange;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
//    textField.keyboardType = UIKeyboardTypeNumberPad;
    
    //    int offset = 350;//键盘高度350
    //    NSTimeInterval animationDuration = 0.30f;
    //    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
    //    [UIView setAnimationDuration:animationDuration];
    //    float width = self.view.frame.size.width;
    //    float height = self.view.frame.size.height;
    //    if(offset > 0)
    //    {
    //        CGRect rect = CGRectMake(0.0f, -offset,width,height);
    //        self.view.frame = rect;
    //    }
    //    [UIView commitAnimations];
    
    if (textField == feiyongjineTxt)
    {
        textField.keyboardType = UIKeyboardTypeNumberPad;
    }

    [feiyongmingchengTxt setEnabled:YES];
    
    //将scrollView上托到最大位置
    [[NSNotificationCenter defaultCenter] postNotificationName:@"mm_addAndModifyViewControllerScrollViewScroll" object:nil];
}

//得到列表中的最大序号
-(NSInteger)getTheMaxNumber
{
    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
    
    NSArray *arrTmp = [[[[modelIns.arrForResults objectAtIndex:modelIns.nRowForResults] objectForKey:@"indicationList"] objectAtIndex:modelIns.nRowForIndicationList] objectForKey:@"otherChargeList"];
    
    NSInteger nMaxNumber = 0;
    
    for (int i = 0; i<[arrTmp count]; i++)
    {
        NSString *strTmp = [[arrTmp objectAtIndex:i] objectForKey:MM_OTHER_CHARGE_OTHER_CHARGE_NUMBER_KEY_STR_];
        nMaxNumber = nMaxNumber < [strTmp integerValue] ? [strTmp integerValue] : nMaxNumber;
    }
    
    return nMaxNumber;
}

//根据ID取名字
-(NSString *)getNameByServiceId:(NSString *)serviceId
{
    for (int i = 0; i<[self.arrOriginalDataForServiceType count]; i++)
    {
        NSString *strId = [[self.arrOriginalDataForServiceType objectAtIndex:i] objectForKey:@"serviceTypeId"];
        NSString *strName = [[self.arrOriginalDataForServiceType objectAtIndex:i] objectForKey:@"serviceTypeName"];
        if ([serviceId isEqualToString:strId])
        {
            return strName;
        }
    }
    return @"";
}

-(NSString *)getNameByRepairId:(NSString *)RepairId
{
    for (int i = 0; i<[self.arrOriginalDataForRepairType count]; i++)
    {
        NSString *strId = [[self.arrOriginalDataForRepairType objectAtIndex:i] objectForKey:@"repairTypeId"];
        NSString *strName = [[self.arrOriginalDataForRepairType objectAtIndex:i] objectForKey:@"repairTypeName"];
        if ([RepairId isEqualToString:strId])
        {
            return strName;
        }
    }
    return @"";
}

@end
